package com.yuhs.zixing.pay.service.merchant.impl;

import com.yuhs.zixing.pay.dal.merchant.dto.PayMerchantInfoDTO;
import com.yuhs.zixing.pay.manager.merchant.MerchantManager;
import com.yuhs.zixing.pay.service.merchant.MerchantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName MerchantServiceImpl
 * @Description 商户service实现类
 * @Author yuhs
 * @CreateDate 2020/12/4
 **/
@Slf4j
@Component
public class MerchantServiceImpl implements MerchantService {

    @Resource
    MerchantManager merchantManager;

    /**
     * 通过商户号获取商户信息
     *
     * @param merchantNo
     * @return
     */
    @Override
    public PayMerchantInfoDTO getMerchantInfoByMerchantNo(String merchantNo) {
        return merchantManager.getPayMerchantInfoByMerchantNo(merchantNo);
    }

    /**
     * 添加商户
     *
     * @param payMerchantInfoDTO
     * @return
     */
    @Override
    public Boolean addMerchant(PayMerchantInfoDTO payMerchantInfoDTO) {
        if (getMerchantInfoByMerchantNo(payMerchantInfoDTO.getMerchantNo()) != null) {
            log.info("{} 该商户已经添加", payMerchantInfoDTO.getMerchantNo());
            return Boolean.FALSE;
        }
        return merchantManager.addMerchant(payMerchantInfoDTO);
    }
}
